Component({
    data: {
        selected: 0,
        color: "#888888",
        selectedColor: "#1296db",
        list: [{
            pagePath: "/pages/life/life-main/life-main",
            text: "服务号"
        }, 
        // {
        //     pagePath: "/pages/car/car-main/car-main",
        //     text: "找车"
        // }, 
        {
            pagePath: "/pages/sessions/sessions-main/sessions-main",
            text: "消息"
        }, {
            pagePath: "/pages/mine/mine-main/mine-main",
            text: "我的"
        }]
    },

    lifetimes: {
        attached() {
            // const pages = getCurrentPages();
            // if (pages.length) {
            //     const currentPage = pages[pages.length - 1].route;
            //     console.log("currentPage", currentPage);
            //     const selected = this.data.list.findIndex(item => item.pagePath === '/' + currentPage);
            //     console.log("selected", selected);
            //     this.setData({
            //         selected: selected !== -1 ? selected : 0
            //     });
            // }
        }
    },

    methods: {
        onSwitchTab(index) {
            const data = this.data.list[index];
            const url = data.pagePath;
            console.log("onSwitchTab", index, url);
            wx.switchTab({url}).then(() => {
                console.log("switchTab success", url);
                wx.setNavigationBarTitle({
                    title: data.text,
                });
                this.setData({
                    selected: index
                });
            }).catch(err => {
                console.error("switchTab error", err);
            });
        },

        switchTab(e) {
            const data = e.currentTarget.dataset;
            const url = data.path;
            console.log("switchTab", data.index, url);
            // this.onSwitchTab(data.index);
            wx.switchTab({url});
        }
    }
})
